package com.mpgame.database.mysql.mapper.verify;

import java.sql.Timestamp;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.mpgame.database.mysql.model.verify.Account;

import org.apache.ibatis.annotations.Param;

@Mapper
public interface AccountMapper {
    @Insert("INSERT INTO account (username, nickname, email, phone, avatar_url, status, password, created_at, last_login_at, last_login_ip) VALUES (#{username}, #{nickname}, #{email}, #{phone}, #{avatarUrl}, #{status}, #{password}, #{createdAt}, #{lastLoginAt}, #{lastLoginIp})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Account account);

    @Select("SELECT * FROM account WHERE id = #{id}")
    Account selectById(@Param("id") int id);

    @Select("SELECT * FROM account WHERE username = #{username} AND status = 0")
    Account selectByUsername(@Param("username") String username);

    @Update("UPDATE account SET last_login_at = #{lastLoginAt}, last_login_ip = #{lastLoginIp} WHERE username = #{username}")
    int updateLastLogin(@Param("username") String username, @Param("lastLoginAt") Timestamp last_login_at, @Param("lastLoginIp") String last_login_ip);
}
